import { request } from '@/utils/request'
import type {
  User,
  CodeType,
  UserInfo,
  PatientList,
  Patient
} from '@/types/user'

/**
 * 手机号密码登录
 * @param mobile
 * @param password
 */
export const loginByPasswordApi = (mobile: string, password: string) => {
  return request<User>('/login/password', 'post', { mobile, password })
}

/**
 * 获取收集验证码
 * @param mobile 手机号
 * @param type 获取验证码类型
 */
export const sendMobileCode = (mobile: string, type: CodeType) => {
  return request<string>('/code', 'get', { mobile, type })
}

/**
 * 验证码登录
 * @param mobile
 * @param code
 */
export const loginByCodeApi = (mobile: string, code: string) => {
  return request<User>('/login', 'POST', { mobile, code })
}

/**
 * 获取用户信息
 */
export const getUserInfoApi = () => {
  return request<UserInfo>('/patient/myUser')
}

/**
 * 获取患者列表
 */
export const getPatientListApi = () => {
  return request<PatientList>('/patient/mylist')
}

/**
 * 添加患者
 * @param patient 患者信息
 */
export const addPatientApi = (patient: Patient) => {
  return request('/patient/add', 'POST', patient)
}

/**
 * 编辑患者
 * @param patient 患者参数
 */
export const editPatientApi = (patient: Patient) => {
  return request('/patient/update', 'PUT', patient)
}

export const delPatientApi = (id: string) => {
  return request(`/patient/del/${id}`, 'DELETE')
}

export const loginByQQ = (openId: string) =>
  request<User>('/login/thirdparty', 'POST', { openId, source: 'qq' })

export const bindMobile = (data: {
  mobile: string
  code: string
  openId: string
}) => request<User>('/login/binding', 'POST', data)
